# example7_5_pd_readsql_sqlite.py
# coding=utf-8
import pandas as pd
from sqlalchemy import create_engine
import sqlite3

# 建立与dbtest子目录下MyDB.sqlite3数据库的连接
engine = create_engine("sqlite:///dbtest/MyDB.sqlite3")

sql = "select * from persons"
df = pd.read_sql(sql, con=engine, index_col="index")

print(df)

# 关闭数据库连接
engine.dispose()


conn = sqlite3.connect("dbtest/MyDB.sqlite3")
query = "SELECT * FROM persons"
df_from_db = pd.read_sql_query(query, conn)
print(df_from_db)
